<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>提交申请</title>
    <link rel="stylesheet" type="text/css" href="../../../css/aui/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../../css/html/issued/post_your_want_frm.css" />
    <style>
        .up_image_box {
            display: flex;
            justify-content: space-between;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="aui-content aui-margin-b-15">
            <ul class="aui-list aui-form-list">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner" @click="openLevel()">
                        <div class="aui-list-item-label">申请级别</div>
                        <div class="aui-pull-right" style="margin-right:0.75rem;width:100%;text-align:right;">
                            {{apply.work_cate_level_name}}
                        </div>
                    </div>
                </li>
            </ul>

            <div>
                <div class="aui-content-padded">
                    <div style="margin:1rem 0 0.5rem 0;">申请概述 <small>（选填项）</small></div>
                    <div><textarea class="textarea" v-model="apply.reason" placeholder="请详细描述申请原由">{{apply.reason}}</textarea></div>
                </div>
            </div>
            <div style="margin-top:5rem;padding:0 0.75rem;">
                <div class="btn" @click="submit()" style="width:100%;">立即提交</div>
            </div>
        </div>
    </div>
</body>
<script src="../../../script/api.js" charset="utf-8"></script>
<script src="../../../script/aui/aui-tab.js" charset="utf-8"></script>
<script src="../../../script/common/jquery-3.3.1.min.js" charset="utf-8"></script>
<script src="../../../script/common/check.js" charset="utf-8"></script>
<script src="../../../script/common/common.js" charset="utf-8"></script>
<script src="../../../script/common/config.js" charset="utf-8"></script>
<script src="../../../script/common/vue.min.js" charset="utf-8"></script>
<script>
    var statusBarHeight = '';
    apiready = function() {
        api.parseTapmode();

        vm.init();
        // $toast(api.pageParam.type);
    }

    var vm = new Vue({
        el: "#app",
        data: {
            apply: {
                user_id: '',
                work_cate_level: "",
                work_cate_level_name: "请选择",
                reason: '',
                user_type: ''
            }
        },
        methods: {
            init() {
                var userInfo = get_local("userInfo");
                this.apply.user_id = userInfo.user_id;
                this.apply.user_type = userInfo.user_type;
                this.getStatusBarHeight();
            },
            openLevel() {
                var url = '../../city/level_win.html';
                api.openFrame({
                    name: 'mask',
                    url: url,
                    rect: {
                        x: 0,
                        y: api.pageParam.headerH + statusBarHeight,
                        w: 'auto',
                        h: 'auto'
                    },
                    bgColor: 'rgba(0,0,0,0.5)', //主要是这里起作用哦
                    pageParam: {
                        name: api.winName,
                        frameName: api.frameName,
                    }
                });
            },
            submit() {
                var userInfo = get_local('userInfo');
                if (this.apply.work_cate_level === '') {
                    $toast("请选择级别");
                    return;
                } else if (!is_define(this.apply.reason)) {
                    $toast("请填写申请原由");
                    return;
                }
                var data = {
                    user_id: userInfo.user_id,
                    work_cate_level: this.apply.work_cate_level,
                    reason: this.apply.reason,
                    user_type: userInfo.user_type
                };
                // TODO:申请工种更改 -- 工种级别格式不清楚
                _ajax(Config.api.UserApplyWorkCateLevel, data, function(ret) {
                    if (ret.code === 200) {
                        $toast("提交成功");
                        setTimeout(function() {
                            close_w();
                        }, 500);
                    } else {
                        $toast("提交失败");
                    }
                });
            },
            getStatusBarHeight() {
                var systemType = api.systemType;
                var statusBar = api.require('statusBar');
                if (systemType == "ios") {
                    statusBarHeight = api.safeArea.top;
                } else {
                    statusBar.getStatusBarHeight(function(ret, err) {
                        statusBarHeight = ret.statusHeight;
                    });
                }
            }
        }
    });

    function setLevel(data) {
        if (data) {
            vm.apply.work_cate_level_name = data.leval_name;
            vm.apply.work_cate_level = data.leval_id;
        }
    }

    function addImg(e) {
        api.actionSheet({
            title: '上传头像',
            cancelTitle: '关闭',
            buttons: ['图片库', '相机 ', '相册']
        }, function(ret, err) {
            var index = ret.buttonIndex;
            var type = new Array('library ', 'camera', 'album');
            if (index != 4) {
                api.getPicture({
                    sourceType: type[index - 1],
                    encodingType: 'jpg',
                    mediaValue: 'pic',
                    destinationType: 'base64',
                    allowEdit: true,
                    quality: 50,
                    saveToPhotoAlbum: false
                }, function(ret, err) {
                    if (ret) {
                        if (ret.data) {
                            $(e).find('img').attr('src', ret.data).css('width', '100%');
                        }
                    }
                });
            }
        });
    }
</script>

</html>
